/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package crashManager;

import gameState.Player;
import java.util.ArrayList;

/**
 *
 * @author DEX
 */
public class DeathList {

    private static final DeathList DEATHLIST_INSTANCE = new DeathList();

    private ArrayList<Player> deathPlayers = new ArrayList<Player>();

    private DeathList(){};

    public static DeathList getInstance(){
        return DEATHLIST_INSTANCE;
    }


    public void addDeathPlayer(Player p){
        deathPlayers.add(p);
    }

    public void removeDeathPlayer(Player p){
        boolean deleted=false;
        int i=0;
        while(!deleted && i<deathPlayers.size()){
            if(p.equalPlayer(deathPlayers.get(i))){
                deathPlayers.remove(i);
            }
            i++;
        }
    }

    public boolean isEmpty(){
        return deathPlayers.size()==0;
    }

    public Player getDeathPlayer(int i){
        return deathPlayers.get(i);
    }

    public int size(){
        return deathPlayers.size();
    }

    public boolean containPlayer(Player p){
        boolean deleted=false;
        int i=0;
        while(!deleted && i<deathPlayers.size()){
            if(p.equalPlayer(deathPlayers.get(i))){
                return true;
            }
            i++;
        }
        return false;
    }


    public void removeAllFromDeathList(){
        while(!deathPlayers.isEmpty()){
            deathPlayers.remove(0);
        }
    }
    

    public void printDeathList(){
        printDeathList("");
    }


    public void printDeathList(String title){
        System.out.println(title);
        System.out.println("       [DEATHLIST]");
        for(int i=0; i<deathPlayers.size(); i++){
            System.out.println("["+i+"]["+deathPlayers.get(i).getIp()+"]["+deathPlayers.get(i).getName()+"]");
        }
    }

}
